import type { App } from 'vue'
import PrimeVue from 'primevue/config'
import ToastService from 'primevue/toastservice'
import ConfirmationService from 'primevue/confirmationservice'
import { useLocaleStore } from '@/stores/useLocaleStore'
import { storeToRefs } from 'pinia'

import 'primeicons/primeicons.css'
import { useThemeStore } from '@/stores/useThemeStore'

export function setupPrimeVuePlugins(app: App) {
  const themeStore = useThemeStore()
  const localeStore = useLocaleStore()
  const { primevueLocale } = storeToRefs(localeStore)
  app.use(ToastService)
  app.use(ConfirmationService)
  app.use(PrimeVue, {
    ripple: true,
    unstyled: false,
    theme: {
      preset: themeStore.CurrentTheme,
      useDefaultOptions: true,
      options: {
        darkModeSelector: '.app-dark',
      },
    },
    locale: primevueLocale.value,
  })
  themeStore.initTempTheme()
}
